package com.heima.user.controller;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.dtos.LoginDto;
import com.heima.user.service.ApUserService;
import com.heima.user.utils.SendSms;
import com.heima.utils.common.ValidateCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
@RequestMapping("/api/v1/login")
@Api(value = "app端用户登录-控制器")
public class ApUserLoginController {


    @Autowired
    private ApUserService apUserService;

    @PostMapping("/login_auth")
    @ApiOperation("用户登录")
    public ResponseResult login(@RequestBody LoginDto dto) {
        return apUserService.login(dto);
    }

    /**
     * 短信发送
     *
     * @param dto
     * @param session
     * @return
     */
    @PostMapping("/sendMsg")
    public ResponseResult sendMsg(@RequestBody LoginDto dto, HttpSession session) {
        return apUserService.sendMsg(dto, session);
    }

    /**
     * 用户点击注册，前端传了手机和code过来
     *
     * @param map
     * @return
     */
    @PostMapping("/regist")
    public ResponseResult regist(@RequestBody Map<String, Object> map) {
        return apUserService.regist(map);
    }


}